/*
* TOCN.H
* Author:YevgenyLiu
*/
#include"stdio.h"
#include"string.h"
#include"graphics.h"

#define UNS unsigned

#ifndef TOCN_H
#define TOCN_H
int disp_hz(int left,int top,UNS char byte1,UNS char byte2,int color)
{
	FILE *hzkfile;
	UNS char buf[32];
	UNS char mark;
	long p;
	int y,i,j,quma,weima;
	hzkfile=fopen("..\\HZK16","rb");
	if(hzkfile==NULL) return -1;
	if((byte1>=0xa1&&byte1<=0xfe)&&(byte2>=0xa1&&byte2<=0xfe))
	{
		quma=byte1-0xa0;
		weima=byte2-0xa0;
		p=(quma-1)*94+weima-1;
		p*=32;
		fseek(hzkfile,(long)p,SEEK_SET);
		fread(buf,sizeof(UNS char),32,hzkfile);
		fclose(hzkfile);
		for(i=0,y=top;i<31;i+=2,y++)
			for(mark=0x80,j=0;mark>0;mark=mark>>1,j++)
			{
				if((buf[i]&mark)!=0) putpixel(left+j,y,color);
				if((buf[i+1]&mark)!=0) putpixel(left+j+8,y,color);
			}
	}
	else
		return 0;
	fclose(hzkfile);
	return 1;
}
int OutTextxy(int x,int y,char *p,int color)
{
	int oldcolor=getcolor();
	setcolor(color);
	while(*p)
	{
		if(((UNS char)*p>=0xa1&&(UNS char)*p<=0xfe)&&((UNS char)*(p+1)>=0xa1&&(UNS char)*(p+1)<=0xfe))
		{
			if((x+16-1)>getmaxx()||(y+16-1)>getmaxy()) return 0;
			disp_hz(x,y,*p,*(p+1),color);
			p+=2;
			x+=16+2;
			moveto(x,y);
		}
		else
		{
			char q[2];
			moveto(x,y);
			*q=*p;
			*(q+1)='\0';
			settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
			outtextxy(x,y+4,q);
			x+=8+1;
			p++;
		}
	}
	setcolor(oldcolor);
	return 1;
}
#endif